<template>
	<view class="equip_detail">
		<NavigationTitle :title="type=='edit'?'流程详情':'流程发起'"
			style="color: #000;background: #fff;position: fixed;width: 100%;z-index: 5;">
			<template slot="left_con">
				<image class="back_icon" src="@/static/common/back.png" mode="widthFix" @tap="backSelf" />
			</template>
		</NavigationTitle>
		<view class="status-bar"></view>
		<view class="main">
			<uni-segmented-control v-if="type=='edit'&&(listKey=='2'||listKey=='3')" class="uni-steps"
				:current="stepsKey" :values="['流程信息', '审批进度']" @clickItem="onClickItem" />
			<view v-if="stepsKey==0">
				<uni-forms ref="taskForm" :modelValue="baseFormData" class="form_main">
					<uni-forms-item label="流程名称:" name="pdid">
						<input class="uni_easyinput" v-model="pdid.name" placeholder="请选择流程名称" :disabled="type=='edit'"
							inputmode="none" @focus.capture="selectPdid" @blur="()=>blurPdid" :clearable="false" />
					</uni-forms-item>
					<view v-if="pdid.key=='excavate'">
						<uni-forms-item label="开始时间:" name="beginTime">
							<uni-datetime-picker type="datetime" v-model="baseFormData.beginTime" placeholder="请选择时间"
								:disabled="type=='edit'" />
						</uni-forms-item>
						<uni-forms-item label="结束时间:" name="endTime">
							<uni-datetime-picker type="datetime" v-model="baseFormData.endTime" placeholder="请选择时间"
								:disabled="type=='edit'" />
						</uni-forms-item>
						<uni-forms-item label="工作地点:" name="workerPlace">
							<uni-easyinput v-model="baseFormData.workerPlace" placeholder="请输入工作地点"
								:disabled="type=='edit'" />
						</uni-forms-item>
						<uni-forms-item label="参与公司:" name="companyNameList">
							<view class="users_box" @click="()=>toggle(compSelect.compNameId,'comp')">
								<text>{{compSelect.compNameStr}}</text>
							</view>
						</uni-forms-item>
						<uni-forms-item label="参与员工:" name="workerIdList">
							<view class="users_box" @click="()=>toggle(userSelect.userId,'user')">
								<text>{{userSelect.userStr}}</text>
							</view>
							<!-- <uni-easyinput type="textarea" v-model="users" placeholder="请选择设备绑定用户" :adjust-position='false'
								:disabled="!authorList.includes('system_device_edit')"
								@focus="(e)=>toggle(e,users)"></uni-easyinput> -->
						</uni-forms-item>
						<uni-forms-item label="项目资料:" name="documentIdList">
							<view class="users_box" @click="()=>toggle(fileSelect.fileId,'file')">
								<text>{{fileSelect.fileStr}}</text>
							</view>
						</uni-forms-item>
						<uni-forms-item label="任务事由:" name="reason">
							<uni-easyinput type="textarea" v-model="baseFormData.reason" :disabled="type=='edit'"
								placeholder="事由描述"></uni-easyinput>
						</uni-forms-item>
					</view>
					<view v-if="pdid.key=='fileApplication'">
						<uni-forms-item label="申请文件:" name="applyFileList">
							<view class="users_box" @click="()=>showDrawer(applyFileList.documentIdList)">
								<text>{{applyFileList.fileStr}}</text>
								<!-- <text>{{applyFileList.fileStr.replace(/\s+/g, '')}}</text> -->
							</view>
						</uni-forms-item>
						<uni-forms-item label="文件所属公司名称:" name="applyFileList">
							<view class="users_box">
								<text>{{applyFileList.documentCompanyName}}</text>
							</view>
						</uni-forms-item>
						<uni-forms-item label="任务事由:" name="reason">
							<uni-easyinput type="textarea" v-model="baseFormData.reason" :disabled="type=='edit'"
								placeholder="事由描述"></uni-easyinput>
						</uni-forms-item>
					</view>
					<view v-if="pdid.key=='notice'|| pdid.key=='report'">
						<uni-forms-item label="主题:" name="theme">
							<uni-easyinput v-model="baseFormData.theme" placeholder="请输入主题"
								:disabled="type=='edit'" />
						</uni-forms-item>
						<uni-forms-item label="内容:" name="reason">
							<uni-easyinput type="textarea" v-model="baseFormData.reason" placeholder="请输入内容"
								:disabled="type=='edit'" />
						</uni-forms-item>
						<uni-forms-item label="选择图片:" name="pictureList">
							<view class="picture-body">
								<lsj-upload ref="lsjUpload" childId="upload1" width="50%" height="auto" :option="option" :count="3"
									:size=50 :instantly="false" :multiple="true" :formats='formats' @uploadEnd="onuploadEnd"
									@progress="onprogre" @change="changeFile" v-if="type=='add'">
									<button type="primary" size="mini">选择</button>
								</lsj-upload>
								<button type="primary" size="mini" v-if="type=='add'" @click="clearPic">清空</button>
								<uni-file-picker :readonly="true" v-model="files"  ref="files" :auto-upload="false"></uni-file-picker>
							</view>
						</uni-forms-item>
						<uni-forms-item label="接收公司:" name="receiverCompanyNameList">
							<view class="users_box" @click="()=>toggle(compSelect.compNameId,'comp')">
								<text>{{compSelect.compNameStr}}</text>
							</view>
						</uni-forms-item>
						<uni-forms-item label="接收员工:" name="receiverIdList">
							<view class="users_box" @click="()=>toggle(userSelect.userId,'user')">
								<text>{{userSelect.userStr}}</text>
							</view>
						</uni-forms-item>
					</view>
				</uni-forms>
				<!-- <uni-steps :options="taskHistory" active-color="#007AFF" :active="active" direction="column" /> -->
				<button v-if="type=='add'" type="primary" @click="subUser" style="width: 40%; margin: auto;">提交</button>
				<button v-if="type=='edit'&&listKey=='2'" type="warn" @click="changeTask('stop')"
					style="width: 40%;margin: auto;">中止流程</button>
				<button v-if="type=='edit'&&listKey=='1'" type="primary" @click="changeTask('run')"
					style="width: 40%;margin: auto;">激活流程</button>
				<view v-if="type=='edit'&&(listKey=='4'||listKey=='5')"
					style="display: flex;align-items: center;justify-content:space-around;">
					<button type="primary" @click="completeTask" style="width: 40%;">审批</button>
					<button v-if="listKey=='4'" type="primary" @click="changeTask('run')"
						style="width: 40%;">激活流程</button>
					<button v-if="listKey=='5'" type="warn" @click="changeTask('stop')"
						style="width: 40%;">中止流程</button>
				</view>
			</view>
			<view v-if="stepsKey==1" class="proSteps">
				<ProcessSteps v-if="taskHistory.length!=0" :data='taskHistory' />
				<view v-if="pdid.key=='notice'|| pdid.key=='report'" class="mesBox">
					<view></view>
					<view v-for=" (value,index) in messageState" :key="index" class="mesItem">
						<view>{{value.state}}:</view>
						<text v-for=" (v,i) in value.userList" :key="i" class="mesUser">
							{{v.receiverName}},
						</text>
					</view>
				</view>
			</view>
		</view>

		<uni-drawer ref="showFile" mode="right" :width="340" :maskClick='false'>
			<view class="status-bar"></view>
			<view class="drawerFile">
				<view class="tab_select">
					<text class="seleName">选择公司：</text>
					<uni-data-select v-model="seleValue" :localdata="compList" placeholder="请选择公司" :clear="false"
						@change="changeComp">
					</uni-data-select>
				</view>
				<scroll-view scroll-y="true" @scrolltolower="scrolltoupper" :scroll-top="scrollTop" @scroll="scrollFile"
					class="fileList">
					<view class="file_item" v-for="v in tableData " :key="v.id" @tap="checkFileValue(v)"
						:style="getCheck(v)?'background-color: #007aff;color:#fff':'background-color: #eee;color:#000'">
						<text>{{v.fileName}}</text>
					</view>
					<text v-if="tableData.length==0" class="noList">暂无文件</text>
					<uni-load-more v-if="tableData.length>9" :status="status" />
				</scroll-view>
				<view style="padding: 20rpx;display: flex;justify-content:space-between;align-items: center;">
					<text>已选择文件:</text>
					<button type="primary" @click="closeDrawer" style="width: 20%;font-size: 28rpx;">确定</button>
				</view>
				<scroll-view scroll-y="true" class="fileBox">
					<view class="box_item" v-for="(v,i) in checkFile" :key="v.id">
						{{v.fileName}}
					</view>
				</scroll-view>
			</view>
		</uni-drawer>
		<uni-popup ref="selectDialog" background-color="#fff">
			<view class="dialog" style="height: 900rpx;width: 100%;">
				<z-paging ref="paging" :fixed="false" v-model="dataList" :loading-more-enabled='false'
					@query="queryList">
					<!-- 如果希望其他view跟着页面滚动，可以放在z-paging标签内 -->
					<view class="dialog_item" v-for="(item,index) in dataList" :key="item.id"
						@click="()=>itemClick(item,index)">
						<view class="item_name">
							<!-- <text>流程名称：</text> -->
							{{item.name}}
						</view>
						<!-- <view class="item-key">
							<text>流程ID：</text>
							{{item.id}}
						</view> -->
					</view>
					<template #loadingMoreNoMore>
						<view style="background-color: black">这是完全自定义的没有更多数据view</view>
					</template>
				</z-paging>
			</view>
		</uni-popup>
		<uni-popup ref="popup" background-color="#fff">
			<view class="popup-content">
				<DaTreeVue2 ref="DaTreeRef" :data="popupTree" labelField="title" valueField="id" defaultExpandAll
					:showCheckbox="true" :defaultCheckedKeys="defaultCheckedKeysValue" @change="handleTreeChange" />
			</view>
		</uni-popup>
		<uni-popup ref="suspendDialog" type="dialog">
			<uni-popup-dialog ref="inputClose" mode="input" title="中止原因" value="" :before-close='true'
				placeholder="请输入内容" @confirm="suspendConfirm" @close="suspendClose"></uni-popup-dialog>
		</uni-popup>
		<uni-popup ref="inputDialog" type="dialog" style="width: 100%;">
			<view class="popupDialog">
				<text class="title">审批结果</text>
				<view class="item">
					<text class="name">是否同意：</text>
					<uni-data-select v-model="resource" :clear="false" :localdata="[
					  { value: 0, text: '同意' },
					  { value: 1, text: '拒绝' },
					]" @change="changeResource"></uni-data-select>
				</view>
				<uni-easyinput type="textarea" v-model="comment" placeholder="请输入审批意见..."></uni-easyinput>
				<view class="popupBtn">
					<button type="reset" @click="dialogClose" style="width: 45%; margin: auto;">取消</button>
					<button type="primary" @click="dialogConfirm" style="width: 45%; margin: auto;">确定</button>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import NavigationTitle from '@/components/navigationTitle'
	import DaTreeVue2 from '@/components/da-tree-vue2/index.vue'
	import {
		system_config
	} from '@/utils/_config.js'
	import {
		showToastMsg,
	} from '@/utils/format.js'
	import {
		mapGetters,
		mapActions
	} from 'vuex'
	import ProcessSteps from '@/components/processSteps/index.vue';
	export default {
		components: {
			NavigationTitle,
			DaTreeVue2,
			ProcessSteps
		},
		computed: {
			...mapGetters(['projectId', 'authorList', 'task'])
		},
		data() {
			return {
				type: '',
				stepsKey: 0,
				rules: {
					businessKey: {
						rules: [{
							required: true,
							errorMessage: '业务编号不能为空！'
						}]
					},
					taskName: {
						rules: [{
							required: true,
							errorMessage: '任务名称不能为空！'
						}]
					},
					processName: {
						rules: [{
							required: true,
							errorMessage: '流程名称不能为空！'
						}]
					},
					startTime: {
						rules: [{
							required: true,
							errorMessage: '启动时间不能为空！'
						}]
					},
				},
				baseFormData: {},
				fileSelect: {
					fileStr: '',
					fileId: [],
				},
				compSelect: {
					compNameStr: '',
					compNameId: [],
					data: []
				},
				userSelect: {
					userStr: '',
					userId: [],
				},
				popupType: '',
				popupTree: [],
				userList: [],
				compList: [],
				fileList: [],
				defaultCheckedKeysValue: [],
				resource: null,
				comment: '',
				taskId: '',
				suspendReason: '',
				dataList: [],
				pdid: {
					name: '',
					id: '',
					key: ''
				},
				page: {
					current: 1,
					size: 10,
				},
				applyFileList: {
					fileStr: '',
					documentIdList: [],
					documentCompanyId: [],
					documentCompanyName: '',
				},
				tableData: [],
				seleValue: uni.getStorageSync('userInfo').compId,
				checkFile: [],
				isMore: false,
				status: 'more',
				scrollTop: 0,
				old: {
					scrollTop: 0
				},
				listKey: '0',
				taskHistory: [],
				messageState: [],
				pictureData:[],//图片数据
				option: {
					url: system_config.apiBaseUrl + '/api/file/upload',
					method: 'put',
					name: 'file',
					header: {
						xtwAuthen: uni.getStorageSync("tokenValue") || '',
					},
					formData: {},
				},
				files: [],
				formats:'',
				param:{},
			}
		},
		onShow() {

		},
		async onLoad(option) {
			uni.showLoading({
				title: '加载中...',
				mask: true
			})
			await this.getUserList()
			await this.getCompList()
			await this.getUserFileList()
			await this.getFileList(this.page)
			if (option.type == 'edit') {
				// this.baseFormData = this.task || {}
				// this.assignee = this.getAssignee(this.task.assignee) || ''
				this.pdid.name = this.task.processName
				this.pdid.key = this.task.processDefinitionKey
				this.getTaskHistory(this.task.processInstanceId)
				if (this.task.processDefinitionKey == 'excavate') {
					this.getTaskInfo(this.task.businessKey)
					// this.getTaskDetail(option.taskId)
				} else if (this.task.processDefinitionKey == 'fileApplication') {
					this.getTaskFileInfo(this.task.processInstanceId)
				} else if (this.task.processDefinitionKey == 'notice'|| this.task.processDefinitionKey=='report') {
					this.getNoticeInfo(this.task.processInstanceId)
					
				}
			}
			console.log(this.task)
			this.listKey = option.key
			this.taskId = option.taskId
			this.type = option.type
			uni.hideLoading()
		},
		methods: {
			clearPic(){
				this.$refs.lsjUpload.clear()
			},
			onprogre(data) {
				// this.files.set(data.name,data);
				this.$forceUpdate();
			},
			onuploadEnd(data) {
				// this.files.set(data.name,data);
				this.$forceUpdate();
				if (data.type == "success") {
					let res = JSON.parse(data.responseText)
					if (res.code == 200) {
						this.pictureData.push(res.msg)
						if(this.pictureData.length==this.files.length){
							let str = ""
							this.pictureData.map(v=>{
								if(str=="") str=v
								else str+=","+v
							})
							this.param.filePath = str
							this.initProcess(this.param)
						}
					}
					else showToastMsg(res.msg)
				}
			},
			changeFile(file) {
				let files = new Map()
				files = [...file.values()]
				files.map(v=>{
					v.url = v.path
				})
				this.files = files
				console.log(this.files)
			},
			onClickItem(e) {
				this.stepsKey = e.currentIndex
				console.log(e)
			},
			async getMesState(id) {
				const res = await this.$api.getMessageState({
					messageId: id
				}).catch(err => {
					console.log(err)
				})
				if (res?.code == 200) {
					this.messageState = res.data

				}
			},
			getCheck(e) {
				return (this.checkFile.find(item => item.id === e.id) !== undefined);
			},
			scrollFile(e) {
				this.old.scrollTop = e.detail.scrollTop
			},
			goTop(e) {
				this.scrollTop = this.old.scrollTop
				this.$nextTick(function() {
					this.scrollTop = 0
				});
			},
			scrolltoupper() {
				console.log('123')
				this.getFileList(this.page, 'more')
			},
			checkFileValue(data) {
				let exists = this.checkFile.find(item => item.id === data.id) !== undefined;
				if (exists) {
					this.checkFile = this.checkFile.filter(item => item.id !== data.id);
				} else {
					this.checkFile.push(data)
				}
				console.log(this.checkFile)
			},
			changeComp() {
				this.page = {
					current: 1,
					size: 10,
				}
				console.log(this.seleValue)
				this.getFileList(this.page, 'refresh')
			},
			showDrawer() {
				if (this.type == 'edit') return
				this.$refs['showFile'].open()
			},
			// 关闭窗口
			closeDrawer() {
				// console.log(this.checkFile)
				let str = "",
					strId = [],
					strCompName = "",
					strCompId = []
				this.checkFile.map(v => {
					strId.push(v.id)
					if (strCompId.length == 0 || strCompId.find(item => item === v.compId) === undefined) {
						strCompId.push(v.compId)
						if (str == "") strCompName = v.compName
						else strCompName += ',' + v.compName
					}
					if (str == "") str = v.fileName
					else str += ',' + v.fileName
				})
				this.applyFileList.fileStr = str
				this.applyFileList.documentIdList = strId
				this.applyFileList.documentCompanyName = strCompName
				this.applyFileList.documentCompanyId = strCompId
				this.$refs['showFile'].close()
			},
			selectPdid() {
				uni.hideKeyboard()
				uni.showLoading({
					title: '加载中...',
					mask: true
				})
				this.$refs.selectDialog.open('bottom');

			},
			blurPdid() {
				this.$refs.selectDialog.close()
			},
			queryList(num, size) {
				this.getProcessList(num, size)
				// console.log(num, size)
			},
			itemClick(v, i) {
				// this.$refs.taskForm.setValue('pdid',v.id)
				console.log(v)
				this.$nextTick(() => {
					this.pdid = {
						name: v.name,
						id: v.id,
						key: v.key
					}
					// this.baseFormData.pdid = v.id
					this.$refs.selectDialog.close()

				})
				this.baseFormData = {}
			},
			async getUserFileList() {
				if (!this.projectId) return
				const res = await this.$api.getUserFileList({
					userId: uni.getStorageSync('userInfo').userId,
					belongProject: this.projectId
				}).catch(err => {
					console.log(err)
				})
				if (res.code == 200 && res.data.length != 0) {
					this.fileList = res.data
				}
			},
			async getProcessList(num = 1, size = 10) {
				const res = await this.$api.getProcessList({
					pageNum: num,
					pageSize: size,
					latest: true
				}).catch(err => {
					console.log(err)
				})
				if (res.code == 200 && res.data.data.length != 0) {
					this.dataList = res.data.data
				}
				console.log(this.dataList)
			},
			getAssignee(str) {
				if (str) return str.slice(1, str.length - 1);
				else return ''
			},
			backSelf() {
				uni.navigateBack({
					delta: 1
				})
			},
			handleTreeChange(allSelectedKeys, currentItem) {
				let arr = '',str = '',that = this
				if (this.popupType == 'user') {
					if (allSelectedKeys.length !== 0) {
						allSelectedKeys.map(v => {
							this.compSelect.data.map(i => {
								if (i.userId == v) {
									if (str == '') str = i.nickName
									else str += "," + i.nickName
								}
							})
						})
					}
					this.userSelect.userStr = str
					this.userSelect.userId = allSelectedKeys
				} else if (this.popupType == 'comp') {
					if (allSelectedKeys.length !== 0) {
						allSelectedKeys.map(v => {
							this.compList.map(i => {
								if (i.compId == v) {
									if (str == '') str = i.compName
									else str += "," + i.compName
								}
							})
						})
					}
					this.compSelect.compNameStr = str
					this.compSelect.compNameId = allSelectedKeys
					getPopupTree(this.userList,this.compSelect.compNameId)||[]
				} else {
					if (allSelectedKeys.length !== 0) {
						allSelectedKeys.map(v => {
							this.fileList.map(i => {
								if (i.id == v) {
									if (str == '') str = i.fileName
									else str += "," + i.fileName
								}
							})
						})
					}
					this.fileSelect.fileStr = str
					this.fileSelect.fileId = allSelectedKeys
				}
				function getPopupTree(list, arr) {
					let data = [],keys=[],str=""
					list.map(v => {
						arr.map(i => {
							if (v.companyId == i) {
								data = data.concat(v.userList)
							}
						})
					})
					data.map(v => {
						let arr = v.roleIdent.split(":")
						if(arr[1]=='fzr'){
							if (str == '') str = v.nickName
							else str += "," + v.nickName
							keys.push(v.userId)
						}
					})
					that.userSelect.userStr = str
					that.userSelect.userId = keys
				}
			},
			async getUserList() {
				const res = await this.$api.getUserlist({
					projectId: this.projectId
				}).catch(err => {
					console.log(err)
				})
				if (res?.code == 200 && res.data.length != 0) {
					this.userList = res.data
					console.log( res.data)
				}
			},
			async getCompList() {
				const res = await this.$api.getComplist({
					projectId: this.projectId
				}).catch(err => {
					console.log(err)
				})
				if (res?.code == 200 && res.data.length != 0) {
					res.data.map(v => {
						v.text = v.compName
						v.value = v.compId
					})
					this.compList = res.data
				}
			},
			async getFileList(page, type) {
				if (this.status == 'loading') return
				let {
					current,
					size
				} = page
				if (type == 'more' && this.isMore) current += 1
				else if (type == 'more' && !this.isMore) return
				if (type == 'refresh') {
					this.goTop()
					this.status = 'more'
					this.page = {
						current,
						size
					}
				}
				this.status = 'loading'
				let param = {
					belongProject: this.projectId,
					compId: this.seleValue,
					current,
					size
				}
				const res = await this.$api.getFileList(param).catch(err => {
					showToastMsg('请求异常！')
				})
				if (res?.code == 200) {
					if (res.data.records.length < size) {
						this.isMore = false
						this.status = 'noMore'
					} else {
						this.isMore = true
						this.status = 'more'
					}
					if (type == 'more') {
						this.tableData = this.tableData.concat(res.data.records)
						this.page = {
							current,
							size
						}
					} else {
						this.tableData = res.data.records
					}
				}
			},
			async getNoticeInfo(id) {
				const res = await this.$api.getNoticeInfo({
					processInsId: id
				}).catch(err => {
					console.log(err)
				})
				if (res?.code == 200) {
					console.log(res)
					this.pdid.id = res.data.pdid
					this.baseFormData = res.data
					this.compSelect.compNameStr = res.data.receiverCompanyNameList
					this.userSelect.userStr = res.data.receiverNameList
					this.files=this.getStrToArr(res.data.filePath)
					this.getMesState(res.data.messageId)
				}
			},
			async getTaskFileInfo(id) {
				const res = await this.$api.getTaskFileInfo({
					processInstanceId: id
				}).catch(err => {
					console.log(err)
				})
				if (res?.code == 200) {
					console.log(res)
					this.pdid.id = res.data.pdid
					this.baseFormData = res.data
					this.applyFileList.fileStr = this.getSplicingArr(res.data.documentNameList)
					this.applyFileList.documentCompanyName = res.data.documentCompanyName

				}
			},
			async getTaskInfo(id) {
				const res = await this.$api.getTaskInfo({
					id
				}).catch(err => {
					console.log(err)
				})
				if (res?.code == 200) {
					this.baseFormData = res.data
					this.pdid.id = res.data.pdid
					this.compSelect.compNameStr = this.getSplicingArr(res.data.companyNameList)
					this.userSelect.userStr = this.getSplicingArr(res.data.workerNameList)
					this.fileSelect.fileStr = this.getSplicingArr(res.data.documentNameList)
				}
			},
			async getTaskDetail(id) {
				const res = await this.$api.getTaskDetail({
					taskId: id
				}).catch(err => {
					console.log(err)
				})
				if (res?.code == 200) {
					this.pdid.id = res.data.pdid
				}
			},
			async getTaskHistory(id) {
				const res = await this.$api.getTaskHistory({
					processInstanceId: id
				}).catch(err => {
					console.log(err)
				})
				if (res?.code == 200) {
					res.data.map(v => {
						v.taskName = v.taskList[0].taskName
						v.isCompletedArr = []
						v.taskList.map(i => {
							v.isCompletedArr.push(i.isCompleted)
						})
					})
					this.taskHistory = res.data

				}
				console.log(this.taskHistory)
			},
			toggle(data, type) {
				if (this.type == 'edit') return
				this.popupType = type
				this.popupTree = []
				let that = this
				if (type == 'user') {
					console.log(this.compSelect.compNameId)
					if (this.compSelect.compNameId == '') return uni.showToast({
						title: '请选择参与公司',
						mask: true,
						icon: 'none'
					})
					this.popupTree = getPopupTree(this.userList, this.compSelect.compNameId) || []
				} else if (type == 'comp') {
					this.compList.map(v => {
						v.id = v.compId
						v.title = v.compName
					})
					this.popupTree = this.compList
					console.log(this.compList)
				} else if (type == 'file') {
					this.fileList.map(v => {
						v.title = v.fileName
					})
					this.popupTree = this.fileList
				} else if (type == 'appleFile') {

				} else {}

				function getPopupTree(list, arr) {
					let data = []
					list.map(v => {
						arr.map(i => {
							if (v.companyId == i) {
								data = data.concat(v.userList)
							}
						})
					})
					data.map(v => {
						v.id = v.userId
						v.title = v.nickName + v.userPhone
					})
					that.compSelect.data = data
					return data
				}
				this.defaultCheckedKeysValue = data
				this.$refs.popup.open('bottom')
			},
			subUser() {
				let param = {},
					that = this
				// if (!this.authorList.includes('system_device_edit')) return showToastMsg('无修改权限！')
				if (!this.projectId) return
				this.$refs.taskForm.validate().then(async res => {
					uni.showLoading({
						title: '加载中...',
						mask: true
					})
					param = res
					param.pdid = that.pdid.id
					if (that.pdid.key == 'excavate') {
						param.projectId = that.projectId
						param.companyNameList = that.compSelect.compNameStr
						param.documentIdList = that.getSplicingArr(that.fileSelect.fileId)
						param.workerIdList = that.getSplicingArr(that.userSelect.userId)
						that.initProcess(param)
					} else if (that.pdid.key == 'fileApplication') {
						param.projId = that.projectId
						param.companyName = uni.getStorageSync('userInfo').compName
						param.documentIdList = that.getSplicingArr(that.applyFileList.documentIdList)
						param.documentCompanyId = that.getSplicingArr(that.applyFileList.documentCompanyId)
						param.documentCompanyName = that.applyFileList.documentCompanyName
						that.initProcess(param)
					} else if (that.pdid.key == 'notice'|| that.pdid.key=='report') {
						param.projectId = that.projectId
						param.receiverCompanyNameList = that.compSelect.compNameStr
						param.receiverIdList = that.getSplicingArr(that.userSelect.userId)
						if(this.files.length==0){
							that.initProcess(param)
						}else{
							that.param = param
							that.$refs.lsjUpload.upload()
						}
						
					}
					
				}).catch(err => {
					console.log(err)
				})

			},
			completeTask() {
				this.comment = ''
				this.resource = null
				this.$refs.inputDialog.open()
			},
			changeTask(type) {
				let that = this
				if (type == "run") {
					uni.showModal({
						title: '提示',
						content: '是否确定激活该流程？',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								that.runTask()
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				} else if (type == 'stop') {
					this.$refs.suspendDialog.open()
				}
			},
			async runTask() {
				if (!this.task.processInstanceId) return
				const res = await this.$api.runTask({
					processInstanceId: this.task.processInstanceId,
				}).catch(err => {
					console.log(err)
				})
				if (res?.code == 200) {
					setTimeout(() => {
						this.backSelf()
					}, 500)
				}
				showToastMsg(res.msg)
				console.log(res)
			},
			async suspendConfirm(e) {
				if (!this.task.processInstanceId || !e) return showToastMsg('请输入中止原因')
				const res = await this.$api.suspendTask({
					processInstanceId: this.task.processInstanceId,
					suspendReason: e
				}).catch(err => {
					console.log(err)
				})
				if (res?.code == 200) {
					setTimeout(() => {
						this.backSelf()
					}, 500)
				}
				showToastMsg(res.msg)
				this.suspendClose()
			},
			suspendClose() {
				this.$refs.suspendDialog.close()
			},
			async rejectTask() {
				let res = await this.$api.rejectTask({
					taskId: this.task.taskId,
					rejectReason: this.comment,
				}).catch(err => {
					console.log(err)
				})
				if (res?.code == 200) {
					setTimeout(() => {
						this.backSelf()
					}, 500)
				}
				showToastMsg(res.msg)
				this.dialogClose()
			},
			async dialogConfirm() {
				if (!this.task.taskId) return
				if (!this.comment || this.resource == null) return showToastMsg('请输入审批结果')
				if (this.resource == 1) return this.rejectTask()
				let obj = {
						comment: this.comment,
						resource: true,
						taskId: this.task.taskId
					},
					res = null
				if (this.pdid.key == 'excavate') {
					res = await this.$api.completeTask(obj).catch(err => {
						console.log(err)
					})
				} else if (this.pdid.key == 'fileApplication') {
					obj.applyUserId = this.baseFormData.applicantId
					obj.fileIds = this.baseFormData.documentIdList
					res = await this.$api.completeTask(obj).catch(err => {
						console.log(err)
					})
				} else return
				if (res?.code == 200) {
					setTimeout(() => {
						this.backSelf()
					}, 500)
				}
				showToastMsg(res.msg)
				this.dialogClose()
			},
			dialogClose() {
				this.$refs.inputDialog.close()
			},
			changeResource(e) {
				console.log(e)
			},
			async initProcess(data) {
				let that = this,
					res = null
				if (that.pdid.key == 'excavate') {
					res = await this.$api.initExcavateProcess(data).catch(err => {
						console.log(err)
					})
				} else if (that.pdid.key == 'fileApplication') {
					res = await this.$api.initteFileProcess(data).catch(err => {
						console.log(err)
					})
				} else if (that.pdid.key == 'notice'|| that.pdid.key=='report') {
					res = await this.$api.initteNoticeProcess(data).catch(err => {
						console.log(err)
					})
				} else return
				if (res?.code == 200) {
					setTimeout(() => {
						that.backSelf()
					}, 1000)
				}
				uni.hideLoading()
				showToastMsg(res.msg)
			},
			async editEquip(data) {
				let that = this
				if (this.device.id) data.id = this.device.id
				else return
				const res = await this.$api.editEquipment(data).catch(err => {
					console.log(err)
				})
				if (res?.code == 200) {
					setTimeout(() => {
						that.backSelf()
					}, 1000)
				}
				showToastMsg(res.msg)
			},
			changeRole(e) {
				console.log(e);
			},
			getSplicingArr(arr) {
				if (arr && arr.length == 0) return ''
				let str = ""
				arr && arr.map(v => {
					if (str == '') str = v + ''
					else str += ',' + v
				})
				return str
			},
			getStrToArr(str){
				let strArr = str.split(","),arr=[];
				strArr.map((v,i)=>{
					arr.push({
						name:i,
						extname:"image",
						url:v
					})
				})
				console.log(arr)
				return arr
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/assets/styles/global.scss';

	view {
		box-sizing: border-box;
	}

	/deep/ .uni-modal__textarea {
		height: 100rpx;
	}

	.equip_detail {
		position: relative;
		height: 100%;
	}

	.uni-steps {
		margin: 20rpx 20rpx 0rpx;
	}

	.proSteps {
		padding: 20rpx 20rpx 0rpx;

		.mesBox {
			margin-top: 50rpx;
			padding: 0 20rpx;

			.mesItem {
				font-size: 34rpx;

				.mesUser {
					padding: 5rpx 10rpx;
					color: #555;
					font-size: 28rpx;
				}
			}
		}
	}

	.form_main {
		padding: 20rpx 20rpx 0rpx;
		min-height: 550rpx;

		.uni_easyinput {
			display: flex;
			box-sizing: border-box;
			flex-direction: row;
			align-items: center;
			border: 1px solid #dcdfe6;
			border-radius: 4px;
			width: auto;
			position: relative;
			overflow: hidden;
			line-height: 1;
			font-size: 14px;
			height: 35px;
			padding-left: 10px;
		}

		.form-item {
			border-bottom: 1px solid #999;

			&>uni-view {
				margin-bottom: 24rpx;
			}

			.form-item-button {
				color: red;
			}

			.item-title {
				font-size: 32rpx;
			}
		}

		.users_box {
			// width: 100%;
			height: 200rpx;
			padding: 10rpx;
			overflow: auto;
			border: 1px solid #dcdfe6;
			border-radius: 10rpx;
			text-align: left;
			line-height: 50rpx;

			&>uni-text {
				font-size: 28rpx;
				// word-break: keep-all;
				white-space: wrap;
			}
		}

		.uni-forms-item {
			flex-direction: column;

			/deep/ .uni-forms-item__label {
				width: auto;
				white-space: nowrap;
				font-size: 32rpx;
			}

			/deep/ .uni-forms-item__content {
				flex: 1;
				min-height: 70rpx;
				padding: 0 12rpx;
			}

			/deep/ .uni-input-placeholder {
				font-size: 28rpx;
			}

			/deep/ .uni-easyinput__placeholder-class {
				font-size: 28rpx;
			}

			/deep/ .uni-select__input-placeholder {
				font-size: 28rpx;
				color: #999;
			}

			/deep/ .is-disabled {
				background-color: #fff !important;
				color: #333;
			}

			/deep/ .uni-date-editor--x__disabled {
				opacity: 1;
			}
		}


	}

	.main {
		padding-top: $System__title_height;
		padding-bottom: 20rpx;
	}

	.popup-content {
		max-height: 800rpx;
		min-height: 500rpx;
		overflow: auto;
		z-index: 999;
	}

	.dialog {
		height: 100%;
		width: 100%;

		.dialog_item {
			position: relative;
			height: auto;
			// display: flex;
			// align-items: center;
			// justify-content: space-between;
			padding: 20rpx 30rpx;
			border: 1px solid #ccc;
			border-radius: 20rpx;
			margin-top: 20rpx;

			&:hover {
				background-color: #007aff;
				color: #fff;
			}
		}
	}

	.popupDialog {
		background-color: #fff;
		width: 100%;
		min-height: 500rpx;
		max-height: 800rpx;
		overflow: auto;
		z-index: 999;
		padding: 30rpx;
		border-radius: 20rpx;

		.title {
			display: block;
			font-size: 36rpx;
			text-align: center;
		}

		.item {
			display: flex;
			align-items: center;
			margin: 20rpx 0;
		}

		.popupBtn {
			display: flex;
			justify-content: space-between;
			margin-top: 20rpx;
		}
	}

	/deep/ .uni-popup__wrapper {
		width: 90%;
		margin: auto;
	}

	/deep/ .uni-popup-dialog {
		width: 100%;
	}

	.drawerFile {
		padding: 24rpx 12rpx;

		/deep/ .uni-table {
			width: 100% !important;
		}

		.tab_select {
			display: flex;
			align-items: center;
			justify-content: center;
			margin-bottom: 25rpx;
		}

		.fileList {
			height: 500rpx;
			border: 1px solid #ddd;
			border-radius: 20rpx;
			padding: 10rpx 0;
			font-size: 24rpx;

			/deep/ .uni-scroll-view-content {
				padding: 0 20rpx;
				box-sizing: border-box;
			}

			.noList {
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translate(-50%, -50%);
				font-size: 36rpx;
				color: #999;
			}

			.file_item {
				width: 100%;
				padding: 20rpx;
				background-color: #eee;
				margin-bottom: 10rpx;
				border-radius: 20rpx;
			}
		}

		.fileBox {
			padding: 10rpx 0;
			width: 100%;
			height: 500rpx;
			border: 1px solid #ccc;
			border-radius: 20rpx;

			/deep/ .uni-scroll-view-content {
				padding: 0 20rpx;
				box-sizing: border-box;
			}

			.box_item {
				display: inline-block;
				font-size: 24rpx;
				width: 100%;
				min-height: 50rpx;
				margin-bottom: 20rpx;
				margin-right: 20rpx;
				padding: 10rpx 10rpx;
				background-color: #eee;
				box-shadow: #ddd 0px 0px 10px;
				// text-overflow: ellipsis;
				// overflow: hidden;
				word-break: break-all;
				white-space: pre-wrap;
			}
		}
	}

	.back_icon {
		width: 37upx;
	}
</style>